unit MainU;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, hooks, StdCtrls;

type
  TMainForm = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Memo1: TMemo;
    cbEatKeyStrokes: TCheckBox;
    Label3: TLabel;
    Edit1: TEdit;
    Button1: TButton;
    Button2: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    KeyboardHook: TKeyboardHook;
    procedure KeyboardHookPREExecute(Hook: THook; var Hookmsg: THookMsg);
  public
    { Public declarations }
  end;

var
  MainForm: TMainForm;

implementation
uses
  Math, Unit1;

{$R *.dfm}

procedure TMainForm.FormCreate(Sender: TObject);
begin
  KeyboardHook := TKeyboardHook.Create;
  KeyboardHook.OnPreExecute := KeyboardHookPREExecute;
  KeyboardHook.Active := True;
end;

procedure TMainForm.KeyboardHookPREExecute(Hook: THook; var Hookmsg: THookMsg);
var
  Key: Word;
begin
  //Here you can choose if you want to return the key stroke to the application or not
  Hookmsg.Result := IfThen(cbEatKeyStrokes.Checked, 1, 0);
  Key := Hookmsg.WPARAM;
  ShowMessage(IntToStr(Hookmsg.Code)+','+IntToStr(Hookmsg.LParam)+','+IntToStr(Hookmsg.Result));
  Label2.Caption := Char(key);
end;

procedure TMainForm.Button1Click(Sender: TObject);
begin
   ShowWindow(Form1.Handle,SW_SHOWNA);
   //Form1.Show;
end;

procedure TMainForm.Button2Click(Sender: TObject);
begin
 form1.ShowModal;
end;

end.

